$(document)
		.ready(
				function() {

					var div = $("#headerLocationElement");

					var options = {
						enableHighAccuracy : true,
						timeout : 5000,
						maximumAge : 0
					};

					function success(pos) {
						var crd = pos.coords;
						var div = $("#headerLocationElement");

//						console.log('Your current position is:');
//						console.log('Latitude : ' + crd.latitude);
//						console.log('Longitude: ' + crd.longitude);
//						console
//								.log('More or less ' + crd.accuracy
//										+ ' meters.');
						initialLocation = new google.maps.LatLng(crd.latitude,
								crd.longitude);
						//div.html("Your Coordinates " + initialLocation);
						codeLatLng(initialLocation.toString());
					}
					;

					function error(err) {
						console.warn('ERROR(' + err.code + '): ' + err.message);
					}

					function codeLatLng(coordinates) {
						// var input = document.getElementById("latlng").value;
						var coords = coordinates.replace("(", "");
						coords = coords.replace(")", "");
						var latlngStr = coords.split(",", 2);
						var lat = parseFloat(latlngStr[0]);
						var lng = parseFloat(latlngStr[1]);
						var latlng = new google.maps.LatLng(lat, lng);
						var geocoder = new google.maps.Geocoder();
						geocoder
								.geocode(
										{
											'latLng' : latlng
										},
										function(results, status) {
											if (status == google.maps.GeocoderStatus.OK) {
												if (results[1]) {
													div.html("You are in "
																	+ results[1].address_components[1].long_name
																	+ ", aren't you? Brayan is currently not close. However, hang in for a get-together.");
												}
											} else {
												div.html("Could not determine your geo location. Pity!");
												console.warn("Could not determine your geo location. " + status);
											}
										});
					}

					navigator.geolocation.getCurrentPosition(success, error,
							options);

				});